package com.taotao.service;

import org.springframework.cloud.client.ServiceInstance;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @program: springcloudAlibaba
 * @ClassName RotationLoadBalancer
 * @description:
 * @author: wangjin
 * @create: 2023-11-07 15:32
 * @Version 1.0
 **/
@Component
public class RotationLoadBalancer implements LoadBalancer {
    private AtomicInteger atomicInteger = new AtomicInteger(0);

    @Override
    public ServiceInstance getSingleAddres(List<ServiceInstance> serviceInstances) {
        int index = atomicInteger.incrementAndGet() % 1;
        ServiceInstance serviceInstance = serviceInstances.get(index);
        return serviceInstance;
    }
}
